package com.bishe.demo.modules.hotel.hotelPolicy.dao;

import com.bishe.demo.modules.hotel.hotelPolicy.entity.Breakfast;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BreakfastDao {
    @Insert("insert into hotel_breakfast values(null,#{offerBreakfast},#{breakfastCost},#{operateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "breakfastId", keyColumn = "breakfast_id")
    void insertBreakfast(Breakfast breakfast);

    @Select("select * from hotel_breakfast hb left join hotel_policy_breakfast hpb on hpb.breakfast_id=hb.breakfast_id where hpb.policy_id=#{policyId}")
    @Results(id = "breakfastResult", value = {
            @Result(column = "breakfast_id", property = "breakfastId"),
            @Result(column = "breakfast_id", property = "breakfastTypes",
                    javaType = List.class,
                    many = @Many(select = "com.bishe.demo.modules.hotel.hotelPolicy.dao.BreakfastTypeDao.getBreakfastTypesByBreakfastId")),
            @Result(column = "breakfast_id", property = "menuTypes",
                    javaType = List.class,
                    many = @Many(select = "com.bishe.demo.modules.hotel.hotelPolicy.dao.MenuTypeDao.getMenuTypesByBreakfastId")),
    })
    Breakfast getBreakfastByPolicyId(int policyId);

    @Delete("delete from hotel_breakfast where breakfast_id=#{breakfastId}")
    void deleteByBreakfastId(int breakfastId);
}
